<style lang="less">
@import "../less/editable-table.less";
</style>

<template>
    <div>
        <Table border :columns="columns" :data="tableData"></Table>
        <Modal v-model="removeModel" width="360">
            <p slot="header" style="color:#f60;">
                <Icon type="information-circled"></Icon>
                <span>删除提示</span>
            </p>
            <div style="text-align:center">
                <p style="font-size:18px;">数据删除后不可恢复，请谨慎操作！</p>
            </div>
            <div slot="footer">
                <Button type="error" @click="remove()" size="large">删除</Button>
                <Button type="info" @click="noRemove()" size="large">取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    props: {
        tableData: Array,
        access: Object
    },
    data () {
        return {
            removeModel:false,
            partyModel: false,
            id: '',
            partySection: {},
            itemTotal: 0,
            mobile: '',
            columns: [
                {
                    title: '序号',
                    type: 'index',
                    width: 80,
                    align: 'center'
                },
                {
                    title: '版本名称',
                    align: 'center',
                    key: 'version_name'
                },
                {
                    title: '版本号',
                    align: 'center',
                    key: 'version_num'
                },
                {
                    title: '版本分类',
                    align: 'center',
                    key: 'app_type',
                    width:90,
                    render: (h, params) => {
                        if (params.row.app_type === 1) {
                            return h('span', 'ios')
                        }  else if(params.row.app_type === 2) {
                            return h('span', 'android')
                        }else {
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: 'app名称',
                    align: 'center',
                    key: 'app_name'
                },
                {
                    title: '升级类型',
                    align: 'center',
                    key: 'update_type',
                    width:90,
                    render: (h, params) => {
                        if (params.row.update_type === 0) {
                            return h('span', '选择升级')
                        }  else if(params.row.update_type === 1) {
                            return h('span', '强制省级')
                        }else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '创建时间',
                    align: 'center',
                    key: 'create_time'
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 210,
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'primary',
                                        size: 'small'

                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: this.access.edit === true ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.infoData(params.row.id)
                                        }
                                    }
                                },
                                '查看详情'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.goRemove(params.index, params.row.id)
                                        }
                                    }
                                },
                                '删除'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'5px',
                                        display: this.access.func === true ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.editData(params.row.id)
                                        }
                                    }
                                },
                                '修改'
                            )
                        ])
                    }
                }
            ],
            partyData: [],
            data: [],
            partyId:''
        }
    },

    methods: {
        init () {
            this.partyData = [];
        },
        editData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'editappversion',
                params: argu
            })
        },
        infoData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'appversioninfo',
                params: argu

            })
        },
        goRemove (index, id) {
            this.modal = true
            this.id = id
            this.index = index
            this.removeModel = true
        },
        remove () {
            let url = 'adminlogin/version/deleteById'
            let data = {
                id: this.id
            }
            ajax
                .formRes(url, data)
                .then(res => {
                    if (res.data > 0) {
                        this.tableData.splice(this.index, 1)
                        this.removeModel = false
                    }
                })
                .catch(res => {
                    console.log('有错误信息')
                    // fail
                })
        },
        noRemove () {
            this.removeModel = false
        },
        cancel () {
            this.partySection = {}
            this.partyModel = false
        }
    },
    created: function () {
        this.init()
    },
    activated () {
        this.init()
    }
}
</script>
